package com.pp.tourism.web.controller;


import com.pp.tourism.web.dto.ApiResponse;
import com.pp.tourism.web.pojo.User;
import com.pp.tourism.web.pojo.UserCommentNode;
import com.pp.tourism.web.service.UserCommentNodeService;
import com.pp.tourism.web.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 用户景点点评评论表 前端控制器
 * </p>
 *
 * @author wjm
 * @since 2019-03-20
 */
@RestController
@RequestMapping("/userCommentNode")
public class UserCommentNodeController {
    @Autowired
    private UserCommentNodeService userCommentNodeService;
    @Autowired
    private UserService userService;

    @ApiOperation("插入回复")
    @PostMapping("/getCommentNodes")
    public ApiResponse getCommentNodes(@RequestBody Map<String,Object> param){
        try {
            //一级id
            String mainUserId = param.get("mainuserid").toString();
            //回复内容
            String comment = param.get("content").toString();
            //景点id
            String scenicId = param.get("scenicid").toString();
            //二级当前层id
            String commentTopId = param.get("topid").toString();

            //获取用户id
            String replayname =param.get("replayname").toString();
            User user = userService.queryUserByName(replayname);

            UserCommentNode userCommentNode = new UserCommentNode();
            userCommentNode.setMainUserId(Integer.valueOf(mainUserId));
            userCommentNode.setComment(comment);
            userCommentNode.setScenicId(Integer.valueOf(scenicId));
            userCommentNode.setCommentTopId(Integer.valueOf(commentTopId));
            userCommentNode.setReplyUserId(user.getId());
            System.out.println(userCommentNode);

            boolean insert = userCommentNodeService.insert(userCommentNode);
            return ApiResponse.ok(insert);
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return ApiResponse.error("500", e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.error("500", "查询失败！");
        }
    }
}

